(function(window) {
    var Subject_tikuCtrl = {
        data: {},
        init: function(data) {
            this.bindEven();
            var w = $(window).width();
            if (view_type == 'Web') {
                var h = $(window).height();
                video_h = h - 50;
                $(".action_box").height(video_h);
                $(".col-group").height(video_h);
                //$("#videoWrapper").width(w);
                $("")
            } else { //手机

                var video_h = w * 0.75;
                $("#videoWrapper").width(w);
            }
            //	hiApp.bind($('[data-page="Subject_tiku"]'));
            $("#videoWrapper").height(video_h);
            $("#videoWrapper object").height(video_h);

            Subject_tikuCtrl.videoPlayer();
            Subject_tikuCtrl.questionHis();
            $(".toolbar").hide();
        },
        afterShow: function() {
            $(".toolbar").hide();
        },
        //显示做题记录
        questionHis: function() {
            $(".all_questions").each(function() {
                if ($(this).find("dd .checked").length > 0) {
                    $(this).find(".sumbit_answer").trigger(hiApp.device.click);
                }
            })
        },


        bindEven: function() {
            var bindings = [{
                // element:document,
                element: '.learnchapter h3',
                event: hiApp.device.click,
                handler: this.show_lesson
            }, {
                element: '.sumbit_answer',
                event: hiApp.device.click,
                handler: this.post_answer
            }, {
                element: '.questions_next',
                event: hiApp.device.click,
                handler: this.questions_next
            }];
            bindEvents(bindings);
        },
        videoPlayer: function() {
            if ($("#videoWrapper").length == 0) return;
            console.log(video_info);
            if (video_info == null) {
                video_info = {};
                video_info.url = 'http://movie.ks.js.cn/flv/other/1_0.mp4';
            }

            //play_url='http://boxphp.oss-cn-hangzhou.aliyuncs.com/video/UpBluRay/0_848x476.mp4';
            play_url = video_info.url;
            //		play_url='http://movie.ks.js.cn/flv/other/1_0.mp4';
            var param = {
                id: 'videoWrapper',
                url: play_url,
                image: video_info.thumbnail,
                //	loaded:"loadedHandler('videoPlayer')",//【初始化调到第几秒
            };
            hiApp.playVideo(param);
        },

        questions_next: function() {
            var _this = $(".all_questions:visible");
            var l = _this.next(".all_questions").length;
            if (l == 0) {
                dialog("恭喜，您已经完所有练习");

            } else {
                _this.hide();
                _this.next(".all_questions").show();
            }
        },

        post_answer: function() {
            var data_id = $(this).attr("data-id");
            var answer_remark = $('[data-id="all_questions_' + data_id + '"]').find(".answer_remark")
            answer_remark.show();
            var anwser = $("#hideQuestionanswer_" + data_id).val();
            var post_anwser = "";
            $('[data-id="all_questions_' + data_id + '"]').find("dd .checked").each(function(i, v) {
                post_anwser += $(v).attr("key");
            });
            if (post_anwser == anwser) {
                var remark = '<span class="glyphicon glyphicon-ok-circle"></span>';
            } else {
                var remark = '<span class="glyphicon glyphicon-remove-circle"></span>';
            }
            //$('[data-id="all_questions_'+data_id+'"]').find("dd").unbind(hiApp.device.click);
            answer_remark.html(remark);
            $("#questions_answer_" + data_id).show();
            $(this).hide();
        },

        show_lesson: function() {
            CM.init("BoxEdu", "Subject_lessonCtrl").show_lesson($(this))
        },


    };

    window.BoxEdu_Subject_tikuCtrl = Subject_tikuCtrl;

})(window);
